package com.grocery.controller;

import com.grocery.bean.Useraddress;
import com.grocery.service.impl.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("address")
public class AddressController {
    @Autowired
    AddressService addressService;

    @RequestMapping("add")
    @ResponseBody
    public int add(Useraddress address) {
        return addressService.addAddress(address);
    }

    @RequestMapping("update")
    @ResponseBody
    public int update(Useraddress address) {
        return addressService.updateAddress(address);
    }

    @RequestMapping("delete")
    @ResponseBody
    public int delete(int id) {
        return addressService.deleteAddress(id);
    }

    @RequestMapping("getaddressbyuserid")
    @ResponseBody
    public List<Useraddress> getbyuserid(int userid) {
        return addressService.getAddressByUserID(userid);
    }

    @RequestMapping("getaddressbyuseridall")
    @ResponseBody
    public List<Useraddress> getbyuseridall(int userid) {
        return addressService.getAddressByUserIDAll(userid);
    }

    @RequestMapping("getaddressbyid")
    @ResponseBody
    public Useraddress getbyid(int id) {
        return addressService.getAddressByID(id);
    }
}
